using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using jtgApp.ItemLoader;

namespace jtgApp.Adapter
{
    public class TJProAdapter: BaseAdapter
    {
        private Context context;
        private readonly TGitemLoader _mySimpleItemLoader;
        public TJProAdapter(Context context, TGitemLoader mySimpleItemLoader)
        {
            this.context = context;
            _mySimpleItemLoader = mySimpleItemLoader;
        }

        public override int Count
        {
            get { return _mySimpleItemLoader.MySimpleItems.Count; }
        }

        public override Java.Lang.Object GetItem(int position)
        {
            return null;
        }

        public override long GetItemId(int position)
        {
            return long.Parse(_mySimpleItemLoader.MySimpleItems[position].productID);
        }
        public override Android.Views.View GetView(int position, Android.Views.View convertView, Android.Views.ViewGroup parent)
        {
            convertView = LayoutInflater.From(context).Inflate(Resource.Drawable.TJProduct, null);
            ImageView _proimage = convertView.FindViewById<ImageView>(Resource.Id.proimage);
            TextView _proname = convertView.FindViewById<TextView>(Resource.Id.proname);
            TextView _price = convertView.FindViewById<TextView>(Resource.Id.price);

            if (_mySimpleItemLoader.MySimpleItems[position].tgImage == null)
            {
                _proimage.SetImageResource(Resource.Drawable.Icon);
            }
            else
            {
                _proimage.SetImageBitmap(_mySimpleItemLoader.MySimpleItems[position].tgImage);
            }

            _proname.Text = _mySimpleItemLoader.MySimpleItems[position].productName.TrimEnd();
            _price.Text = _mySimpleItemLoader.MySimpleItems[position].tgPrice.TrimEnd();
            return convertView;
        }
    }
}